<template>
    <div class="xgdingdan">
    <div class="XgDingdan-xianzhi">
        <el-row>
            <el-col :span="24" class="dingdan-box1" style="border-bottom: 2px solid #E4E4E4">
                <div class="grid-content bg-purple-dark" style="float: left">
                    商品订单列表
                </div>
                <div style="float: right;">
                    <el-button size="mini" style="background-color: #FFFFFF" class="small-button" plain @click="returnPage"><i class="el-icon-arrow-left"></i>返回</el-button>
                    <el-button size="mini" style="background-color: #FFFFFF" class="small-button" @click="shuaxin"><i class="el-icon-refresh-right"></i>刷新</el-button>
                </div>
            </el-col>
            <el-col :span="24" class="dingdan-box1" style="margin-top: 20px">
                <div class="grid-content bg-purple-dark" style="color: black;margin-left: 30px">
                    商品列表
                </div>
                        <el-descriptions direction="vertical" :column="6" border>
                            <el-descriptions-item label="商品图片" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">
                                <el-image
                                        style="width: 100px; height: 100px"
                                        :src="Dingdan.mainImage">
                                </el-image>
                            </el-descriptions-item>
                            <el-descriptions-item label="商品名称" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">
                                {{Dingdan.productName}}<br/>
                                分类：{{Dingdan.categroyId}}
                            </el-descriptions-item>
                            <el-descriptions-item label="价格" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.currentpriceProduct}}</el-descriptions-item>
                            <el-descriptions-item label="编号" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.productCode}}</el-descriptions-item>
                            <el-descriptions-item label="类型" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.categroyId}}</el-descriptions-item>
                            <el-descriptions-item label="小计" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;" content-style="text-align:center;height:80px">{{Dingdan.currentpriceProduct}}</el-descriptions-item>
                        </el-descriptions>
                        <div class="label-one">
                            <div style="float: right;margin-right: 80px;">
                                合计：<span style="color: #F04844">{{Dingdan.currentpriceProduct}}</span>
                            </div>
                        </div>
                        <div style="clear: both"></div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24" class="dingdan-box1" style="margin-top: 260px">
                <div class="grid-content bg-purple-dark" style="margin-left: 30px">
                    修改商品信息
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24" style="margin-top: 30px;background-color: white">
                <el-descriptions direction="horizontal" :column="1" border>
                    <el-descriptions-item label="搜索商品" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">
                        <input style="width: 170px;height: 30px;border-color: #E4E4E4" placeholder="商品名称/货号" v-model="Shop"></input>
                        <el-button type="primary" style="margin-left: 15px" @click="sousuoShopDingdan">搜索</el-button>
                    </el-descriptions-item>
                    <el-descriptions-item label="商品名称" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.productName}}</el-descriptions-item>
                    <el-descriptions-item label="编号" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.productCode}}</el-descriptions-item>
                    <el-descriptions-item label="分类" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.categroyId}}</el-descriptions-item>
                    <el-descriptions-item label="价格" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.currentpriceProduct}}</el-descriptions-item>
                    <el-descriptions-item label="类型" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.orderType}}</el-descriptions-item>
                    <el-descriptions-item label="合计" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">{{Dingdan.currentpriceProduct}} </el-descriptions-item>
                    <el-descriptions-item label="操作" label-style="text-align:center;font:bold 14px 微软雅黑;color:#666666;backgroundColor:#F9FAFC;width:200px;height:50px">
                        <el-button type="primary" @click="XiugaiShop" v-if="xiugai">修改信息</el-button>
                        <el-dialog
                                title="修改信息"
                                :visible.sync="centerDialogVisible"
                                width="70%"
                                center>
                            <div class="dialogDiv">
                                <el-form class="demo-form-inline" @submit.native.prevent :model="form" ref="form">
                                    <el-form-item label="商品名称" :label-width="formLabelWidth" style="width: 350px;margin-left: 33%">
                                        <el-input :placeholder="Dingdan.productName" v-model="form.name" autocomplete="off"></el-input>
                                    </el-form-item>
                                    <el-form-item label="所属分类" :label-width="formLabelWidth" style="width: 350px;margin-left: 33%">
                                        <el-select placeholder="请选择分类" class="select-dingdan" v-model="form.fenlei2" style="width: 260px;">
                                            <el-option
                                                    v-for="item in form.fenlei"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="商品价格" :label-width="formLabelWidth" style="width: 350px;margin-left: 33%">
                                        <el-input :placeholder="Dingdan.currentpriceProduct" v-model="form.price" autocomplete="off" onkeyup="this.value = this.value.replace(/[^\d]/g,'');"></el-input>
                                    </el-form-item>
                                    <el-form-item label="修改图片" :label-width="formLabelWidth" style="width: 350px;margin-left: 33%" ref="crFile">
                                        <el-upload
                                                ref="doctypeCrfile"
                                                class="upload-demo"
                                                accept=".jpg,.png"
                                                :data="ObjectProductCode"
                                                :auto-upload="false"
                                                action="http://localhost:8091/getUpdateImg"
                                                list-type="picture"
                                                :limit="1"
                                                :before-upload="beforA"
                                                :on-exceed="handleExceed"
                                                :on-preview="handlePictureCardPreview"
                                                :on-success="handleSuccess"
                                        >
                                            <el-button size="small" type="primary">点击上传</el-button>
                                            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过20mb</div>
                                        </el-upload>
                                        <el-dialog :visible.sync="dialogTupian">
                                            <img width="100%" :src="dialogImageUrl" alt="">
                                        </el-dialog>
                                    </el-form-item>
                                </el-form>
                            </div>
                            <span slot="footer" class="dialog-footer">
                                <el-button @click="centerDialogVisible = false">取 消</el-button>
                                <el-button type="primary" @click="uploadConfirm">确 定</el-button>
                            </span>
                        </el-dialog>
                    </el-descriptions-item>
                </el-descriptions>
            </el-col>
        </el-row>
    </div>
    </div>
</template>

<script>
    export default {
        inject:['reload'],
        data(){
            return{
                centerDialogVisible: false,
                Dingdan:'',//发送搜索请求后渲染值到页面上
                Shop:'',//input框中的数值
                xiugai:false,//修改信息是否展示
                form:{
                    name:'',
                    fenlei: [{
                        value: '1',
                        label: '书籍'
                    },{
                        value: '2',
                        label: '服装'
                    }],
                    fenlei2:'',
                    price:'',
                },
                formLabelWidth:"90px",
                dialogImageUrl: '',
                dialogTupian:false,
                ObjectProductCode:'',//用于上传文件时的data携带参数 已转成Object类型
            }
        },
        methods:{
            shuaxin(){
                //刷新页面的方法
                this.reload();
            },
            returnPage(){
                //此方法用来返回上一个页面
                if (window.history.length <= 1) {
                    this.$router.push({ path: "/system/storageManagement" });
                    return false;
                } else {
                    this.$router.go(-1);
                }
            },
            async sousuoShopDingdan(){
                //获取订单编号相关联的一切数据
                const {data:res} = await this.$http.post("/selectShop",{
                    "productCode":this.Shop,
                    "productName":this.Shop
                })
                this.Dingdan = res;
                if(res!=''){
                    this.ObjectProductCode = {"productCode":this.Dingdan.productCode};
                    this.xiugai = true;
                    if(this.Dingdan.categroyId == 1){
                        this.Dingdan.categroyId = "书籍"
                    }else {
                        this.Dingdan.categroyId = "服装"
                    }
                }else {
                    this.xiugai = false;
                }
                if (this.Dingdan.orderType == 3){
                    this.Dingdan.orderType = "商品"
                }
            },
            XiugaiShop(){
                this.centerDialogVisible = true
            },
            uploadConfirm(){
                this.$refs.doctypeCrfile.submit();
                this.centerDialogVisible = false;
            },
            beforA(file){
                const isLt20M = file.size / 1024 / 1024 < 20;
                if(!isLt20M){
                    this.$message.error('上传图片的大小不能超过20MB！');
                }
                return true;
            },
            handleExceed(files, fileList) {
                this.$message.warning(`最多上传1个文件`);
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogTupian = true;
            },
            async handleSuccess(response){
                if(response){
                    const {data:res} = await this.$http.post("/UpdateShop",{
                        "productName":this.form.name,
                        "categroyId":this.form.fenlei2,
                        "currentpriceProduct":this.form.price,
                        "originalpriceProduct":this.Dingdan.currentpriceProduct,
                        "productCode":this.Dingdan.productCode
                    })
                    if (res){
                        this.$message.success('修改成功');
                        this.shuaxin();
                    }
                }
            },
        },
        mounted() {
            this.sousuoShopDingdan();
        }
    }
</script>

<style scoped>
    *{
        margin:0px;
        pargin:0px;
    }
    .center{
        margin:0 auto;
    }
    ul li{
        list-style:none;
    }
    a{
        text-decoration:none;
    }
    .XgDingdan-xianzhi{
        width: 1340px;
    }
    .xgdingdan{
        height: 100%;
        width: 100%;
    }
    .dingdan-box1{
        color: #666666;
        line-height: 50px;
        height: 50px;
        background-color: #F3F3F3;
    }
    .label-one{
        height: 60px;
        background-color:#F9FAFC;
        border: 1px solid #EBEEF5;
        font: bold 18px/60px "微软雅黑";
    }
    .dialogDiv{
        width: 100%;
        height: 60vh;
        overflow: scroll;
    }
</style>